﻿using Microsoft.Xna.Framework;
using System.Collections.Generic;

namespace Sparklings.RayTracing
{
    public class ColoredRay : Ray
    {
        public void Apply(IList<LightHittable> segmentsToTest)
        {
            HitDistance = -1.0f;
            foreach (LightHit segmentHit in base.Collide(segmentsToTest))
            {
                Vector2 collidePosRel = (Vector2)segmentHit.Position - segmentHit.Segment.Origin;
                if (segmentHit.Segment.Hit != null)
                {
                    segmentHit.Segment.Hit(this, segmentHit.Segment, collidePosRel);
                }
                float curDist = (Origin - segmentHit.Position).Length();
                if (curDist > HitDistance)
                {
                    HitDistance = curDist;
                }
            }
            HitDistance = HitDistance < 0 ? float.MaxValue : HitDistance;
        }
        public RayColor Color;
        public float HitDistance;
    }
}
